jun.JenisBotolWin = Ext.extend(Ext.Window, {
    title: 'Master Jenis Botol',
    modez: 1,
    width: 400,
    height: 175,
    layout: 'form',
    modal: true,
    padding: 5,
    closeForm: false,
    initComponent: function() {
        this.items = [{
            xtype: 'form',
            frame: false,
            bodyStyle: 'background-color: #E4E4E4; padding: 10px',
            id: 'form-JenisBotol',
            labelWidth: 100,
            labelAlign: 'left',
            layout: 'form',
            ref: 'formz',
            border: false,
            items: [{
                xtype: 'uctextfield',
                fieldLabel: 'Nama Jenis Botol',
                hideLabel: false,
                //hidden:true,
                name: 'jenis_botol_name',
                id: 'jenis_botol_nameid',
                ref: '../jenis_botol_name',
                maxLength: 100,
                //allowBlank: 1,
                anchor: '100%'
            },
            {
                xtype: 'numericfield',
                fieldLabel: 'Harga',
                hideLabel: false,
                //hidden:true,
                name: 'price',
                id: 'priceid',
                ref: '../price',
                maxLength: 30,
                //allowBlank: 1,
                anchor: '80%'
            },
            new jun.comboActive({fieldLabel: "Status", hideLabel: !1, width: 100, height: 20, name: "status", id: "statusid", ref: "../status", hiddenName: "status"})
            ]
        }];
        this.fbar = {
            xtype: 'toolbar',
            items: [{
                xtype: 'button',
                text: 'Simpan',
                hidden: false,
                ref: '../btnSave'
            }, {
                xtype: 'button',
                text: 'Simpan & Tutup',
                ref: '../btnSaveClose'
            }, {
                xtype: 'button',
                text: 'Batal',
                ref: '../btnCancel'
            }]
        };
        jun.JenisBotolWin.superclass.initComponent.call(this);
        //        this.on('activate', this.onActivate, this);
        this.btnSaveClose.on('click', this.onbtnSaveCloseClick, this);
        this.btnSave.on('click', this.onbtnSaveclick, this);
        this.btnCancel.on('click', this.onbtnCancelclick, this);
        if (this.modez == 1 || this.modez == 2) {
            this.btnSave.setVisible(false);
        } else {
            this.btnSave.setVisible(true);
        }
    },

    btnDisabled: function(status) {
        this.btnSave.setDisabled(status);
        this.btnSaveClose.setDisabled(status);
    },

    saveForm: function() {
        this.btnDisabled(true);
        var urlz;
        if (this.modez == 1 || this.modez == 2) {

            urlz = 'JenisBotol/update/id/' + this.id;

        } else {

            urlz = 'JenisBotol/create/';
        }

        Ext.getCmp('form-JenisBotol').getForm().submit({
            url: urlz,
            timeOut: 1000,
            scope: this,
            success: function(f, a) {
                jun.rztJenisBotol.reload();
                jun.rztJenisBotolMaster.reload();
                jun.rztJenisBotolLib.reload();
                var response = Ext.decode(a.response.responseText);
                Ext.MessageBox.show({
                    title: 'Info',
                    msg: response.msg,
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.INFO
                });
                if (this.modez == 0) {
                    Ext.getCmp('form-JenisBotol').getForm().reset();
                    this.btnDisabled(false);
                }
                if (this.closeForm) {
                    this.close();
                }
            },
            failure: function (f, a) {
                switch (a.failureType) {
                    case Ext.form.Action.CLIENT_INVALID:
                        Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                        break;
                    case Ext.form.Action.CONNECT_FAILURE:
                        Ext.Msg.alert(a.response.statusText, a.response.responseText);
                        break;
                    case Ext.form.Action.SERVER_INVALID:
                        Ext.Msg.alert('Failure', a.result.msg);
                }
                this.btnDisabled(false);
            }

        });

    },

    onbtnSaveCloseClick: function() {
        this.closeForm = true;
        this.saveForm(true);
    },

    onbtnSaveclick: function() {
        this.closeForm = false;
        this.saveForm(false);
    },
    onbtnCancelclick: function() {
        this.close();
    }

});